package rss_POJO;

import java.util.Date;
import java.util.Collection;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author RS-team
 */
@Entity
@Table(name = "ALBUM")
//@Table(name = "ALBUM", uniqueConstraints = {
//    @UniqueConstraint(columnNames = {"TITLE"})})
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Album.findAll", query = "SELECT a FROM Album a"),
    @NamedQuery(name = "Album.findByAlbumid", query = "SELECT a FROM Album a WHERE a.albumid = :albumid"),
    @NamedQuery(name = "Album.findByTitle", query = "SELECT a FROM Album a WHERE a.title = :title"),
    @NamedQuery(name = "Album.findByReleasedate", query = "SELECT a FROM Album a WHERE a.releasedate = :releasedate"),
    @NamedQuery(name = "Album.findByType", query = "SELECT a FROM Album a WHERE a.type = :type"),
    @NamedQuery(name = "Album.findByDisknumber", query = "SELECT a FROM Album a WHERE a.disknumber = :disknumber")})
public class Album implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ALBUMID")  // είναι not αλλά nullable και unique ως primary key
        @Basic(optional = false)
        private Integer albumid;
    @Column(name = "TITLE", nullable = false, unique = true, length = 100)  // μοναδικότητα κύριου αναγνωριστικού πεδίου αναζήτησης
        @Basic(optional = false)
        private String title;
    @Column(name = "RELEASEDATE", nullable = true, unique = false)
        @Basic(optional = true)
        @Temporal(TemporalType.DATE)
        private Date releasedate;
    @Column(name = "TYPE", nullable = false, unique = false, length = 10)
        @Basic(optional = false)
        private String type;
    @Column(name = "DISKNUMBER", nullable = false, unique = false)
        @Basic(optional = false)
        private Integer disknumber;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "albumId")
        private Collection<Song> songCollection;
    @ManyToOne(optional = false)
        @JoinColumn(name = "MPCOMPANY_ID", referencedColumnName = "MPCOMPANYID", nullable = false, unique = false)
        private MusicProductionCompany mpcompanyId;
    @ManyToOne(optional = true)
        @JoinColumn(name = "MUSICGROUP_ID", referencedColumnName = "MUSICGROUPID", nullable = true, unique = false)
        private MusicGroup musicgroupId;
    @ManyToOne(optional = true)
        @JoinColumn(name = "ARTIST_ID", referencedColumnName = "ARTISTID", nullable = true, unique = false)
        private Artist artistId;

    /* default constructor */
    public Album() {
    }
    /* "τεμπέλικος" constructor χωρίς τα nullable πεδία */
    public Album(String title, String type, Integer disknumber) {
        this.albumid = null;  // ετσι κι αλλιώς θα το ορίσει η ΒΔ
        this.title = title;
        this.type = type;
        this.disknumber = disknumber;
    }
    /* και ο πλήρης constructor */
    public Album(String title, Date releasedate, String type, Integer disknumber) {
        this.albumid = null;  // ετσι κι αλλιώς θα το ορίσει η ΒΔ
        this.title = title;
        this.releasedate = releasedate;
        this.type = type;
        this.disknumber = disknumber;
    }

    /* getters */
    public Integer getAlbumid() { return albumid; }
    public String getTitle() { return title; }
    public Date getReleasedate() { return releasedate; }
    public String getType() { return type; }
    public Integer getDisknumber() { return disknumber; }
    /* getters για foreign keys */
    public MusicProductionCompany getMpcompanyId() { return mpcompanyId; }
    public MusicGroup getMusicgroupId() { return musicgroupId; }
    public Artist getArtistId() { return artistId; }

    /* setters εκτός ίσως από το primary key */
    public void setAlbumid(Integer albumid) { this.albumid = albumid; }
    public void setTitle(String title) { this.title = title; }
    public void setReleasedate(Date releasedate) { this.releasedate = releasedate; }
    public void setType(String type) { this.type = type; }
    public void setDisknumber(Integer disknumber) { this.disknumber = disknumber; }
    /* setters για foreign keys */
    public void setMpcompanyId(MusicProductionCompany mpcompanyId) { this.mpcompanyId = mpcompanyId; }
    public void setMusicgroupId(MusicGroup musicgroupId) { this.musicgroupId = musicgroupId; }
    public void setArtistId(Artist artistId) { this.artistId = artistId; }

    @XmlTransient
    /* getter και setter για την songCollection */
    public Collection<Song> getSongCollection() {
        return songCollection;
    }
    public void setSongCollection(Collection<Song> songCollection) {
        this.songCollection = songCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (albumid != null ? albumid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Album)) {
            return false;
        }
        Album other = (Album) object;
        if ((this.albumid == null && other.albumid != null) || (this.albumid != null && !this.albumid.equals(other.albumid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "rss_POJO.Album[ albumid=" + albumid + " ]";
    }

}